//创建子进程和重启子进程
const cp = require('child_process');
const fs = require('fs');
const {resolve} = require('path')

;(async () => {
  const indexSrc = resolve(__dirname, './index')
  const childIenx = cp.fork(indexSrc, [])
  childIenx.on('exit', (code) => {
    console.log(`子进程信息` + code);
      
    if (code !== 0) {
      fs.appendFileSync(resolve(__dirname,'./log.txt'), '线程意外退出' + '\n');
      //当子进程意外退出时,重启子进程
      cp.fork(indexSrc, []);
    }
  })
})()
